#include<bits/stdc++.h>
using namespace std;

#define int long long

int const MAXN=1e6+15;
int T;
int n,m,L,V;
int ans1=0,ans2=0;
int MAXN_p;
bool FLAG_A=true,FLAG_B=true,FLAG_C=true;

int d[MAXN],v[MAXN],a[MAXN],p[MAXN],de[MAXN];
int de_pl[MAXN];//de qianzhuiheshuzu

int solve_S(int v_0,int a_0){
	return (V*V-v_0*v_0)/(2*a_0);
}

double d_solve_S(int v_0,int a_0){
	return (V*V-v_0*v_0)*1.0/(2*a_0);
}

void ans_A(){
	for(int i=1;i<=n;i++){
		if(v[i]<=V)continue;
		if(d[i]<=MAXN_p)ans1++;
	}
	printf("%lld ",ans1);
	if(ans1)printf("%lld\n",m-1);
	else printf("%lld\n",m);
}

void ans_B(){
	for(int i=1;i<=n;i++){
		int S=solve_S(v[i],a[i]);
		if(v[i]>V&&d[i]<=MAXN_p)ans1++;
		else if(((d[i]+S)<MAXN_p)&&(d[i]<=MAXN_p))ans1++;
	}
	printf("%lld ",ans1);
	if(ans1)printf("%lld\n",m-1);
	else printf("%lld\n",m);
}

/*void ans_C(){
	for(int i=1;i<=L;i++){
		de_pl[i]=de[i]+de_pl[i-1];
	}
	double S=solve_S(v[i],a[i]);
	for(int i=1;i<=n;i++){
		if(judge(d[i],d[i]+S)){
			ans1++;

		}
	}
}*/


signed main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%lld",&T);
	while(T>0){
		MAXN_p=INT_MIN;
		ans1=0;
		memset(de,sizeof(de),0);
		T--;
		scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
		for(int i=1;i<=n;i++){
			scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
			if(a[i]!=0)FLAG_A=false;
			if(a[i]<=0)FLAG_B=false;
			if(a[i]>=0)FLAG_C=false;
		}
		for(int j=1;j<=m;j++){
			scanf("%lld",&p[j]);
			MAXN_p=max(MAXN_p,p[j]);
			de[p[j]]+=1;
		}

		if(FLAG_A) ans_A();
		else if(FLAG_B) ans_B();
		//else ans_all();
	}
	return 0;
}